
//
// * Copyright (c) 2002-2010 "Neo Technology,"
// *     Network Engine for Objects in Lund AB [http://neotechnology.com]
// *
// * This file is part of Neo4j.
// * 
// * Neo4j is free software: you can redistribute it and/or modify
// * it under the terms of the GNU Affero General Public License as
// * published by the Free Software Foundation, either version 3 of the
// * License, or (at your option) any later version.
// * 
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// * GNU Affero General Public License for more details.
// * 
// * You should have received a copy of the GNU Affero General Public License
// * along with this program. If not, see <http://www.gnu.org/licenses/>.
// 
namespace org.neo4j.graphdb
{

///
/// <summary> * A dynamically instantiated and named <seealso cref="RelationshipType"/>. This class is
/// * a convenience implementation of <code>RelationshipType</code> that is
/// * typically used when relationship types are created and named after a
/// * condition that can only be detected at runtime.
/// * <p>
/// * If all relationship types are known at compile time, it's better to use the
/// * relationship type enum idiom as outlined in <seealso cref="RelationshipType"/>.
/// * <p>
/// * It's very important to note that a relationship type is uniquely identified
/// * by its name, not by any particular instance that implements this interface.
/// * This means that the proper way to check if two relationship types are equal
/// * is by invoking <code>equals()</code> on their <seealso cref="name() names"/>, NOT by
/// * using Java's identity operator (<code>==</code>) or <code>equals()</code> on
/// * the relationship type instances. A consequence of this is that you can NOT
/// * use relationship types in hashed collections such as
/// * <seealso cref="java.util.HashMap HashMap"/> and <seealso cref="java.util.HashSet HashSet"/>.
/// * <p>
/// * However, you usually want to check whether a specific relationship
/// * <i>instance</i> is of a certain type. That is best achieved with the
/// * <seealso cref="Relationship#isType Relationship.isType"/> method, such as:
/// * 
/// * <pre>
/// * <code>
/// * <seealso cref="RelationshipType"/> type = DynamicRelationshipType.<seealso cref="withName(string) withName"/>( "myname" );
/// * if ( rel.<seealso cref="Relationship#isType(RelationshipType) isType"/>( type ) )
/// * {
/// *     ...
/// * }
/// * </code>
/// * </pre> </summary>
/// 
	public sealed class DynamicRelationshipType : RelationshipType
	{
		private string name;
		private DynamicRelationshipType(string name)
		{
			if (name == null)
			{
				throw new IllegalArgumentException("A relationship type cannot " + "have a null name");
			}
			this.name = name;
		}

///    
///     <summary> * Instantiates a new DynamicRelationshipType with the given name, without
///     * creating it in the underlying storage. The relationship type is persisted
///     * only when the first relationship of this type is created.
///     *  </summary>
///     * <param name="name"> the name of the dynamic relationship type </param>
///     * <returns> a DynamicRelationshipType with the given name </returns>
///     * <exception cref="IllegalArgumentException"> if name is <code>null</code> </exception>
///     
		public static DynamicRelationshipType withName(string name)
		{
			return new DynamicRelationshipType(name);
		}

///    
///     <summary> * Returns the name of this relationship type. The name uniquely identifies
///     * a relationship type, i.e. two different RelationshipType instances with
///     * different object identifiers (and possibly even different classes) are
///     * semantically equivalent if they have <seealso cref="string#equals(Object) equal"/>
///     * names.
///     *  </summary>
///     * <returns> the name of the relationship type </returns>
///     
		public string Name()
		{
			return this.name;
		}

///    
///     <summary> * Returns a string representation of this dynamic relationship type.
///     *  </summary>
///     * <returns> a string representation of this dynamic relationship type </returns>
///     * <seealso cref= java.lang.Object#toString() </seealso>
///     
		public override string ToString()
		{
			return "DynamicRelationshipType[" + this.name + "]";
		}

///    
///     <summary> * Implements the identity-based equals defined by {@link Object
///     * java.lang.Object}. This means that this dynamic relationship type
///     * instance will NOT be equal to other relationship types with the same
///     * name. As outlined in the documentation for {@link RelationshipType
///     * RelationshipType}, the proper way to check for equivalence between two
///     * relationship types is to compare their {@link RelationshipType#name()
///     * names}.
///     *  </summary>
///     * <returns> <code>true</code> if <code>other</code> is the same instance as
///     *         this dynamic relationship type, <code>false</code> otherwise </returns>
///     * <seealso cref= java.lang.Object#equals(java.lang.Object) </seealso>
///     
		public override bool Equals(object other)
		{
			return base.Equals(other);
		}

///    
///     <summary> * Implements the default hash function as defined by {@link Object
///     * java.lang.Object}. This means that if you put a dynamic relationship
///     * instance into a hash-based collection, it most likely will NOT behave as
///     * you expect. Please see the documentation of {@link #equals(Object)
///     * equals} and the <seealso cref="DynamicRelationshipType class documentation"/> for
///     * more details.
///     *  </summary>
///     * <returns> a hash code value for this dynamic relationship type instance </returns>
///     * <seealso cref= java.lang.Object#hashCode() </seealso>
///     
		public override int GetHashCode()
		{
			return base.GetHashCode();
		}
	}

}